<template>
  <el-dialog :visible.sync="dialog" title="添加" append-to-body width="800px">
    <!--表格渲染-->
    <el-table v-loading="loading" ref="table" :data="data" size="small" style="width: 100%;">
      <el-table-column type="selection"/>
      <el-table-column label="团队id" prop="team_id"/>
      <el-table-column label="团队名" prop="team_name" />
      <el-table-column label="团队负责人姓名" prop="leader_name"/>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      :current-page="page + 1"
      background
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
    <div slot="footer" class="dialog-footer">
      <el-button size="small" @click="cancel">取消</el-button>
      <el-button :loading="loading" size="small" type="primary" @click="doSubmit()">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import initData from '@/mixins/initData'
import { mapGetters } from 'vuex'

export default {
  mixins: [initData],
  data() {
    return {
      dialog: false, loading: false
    }
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  created() {
    // 获取员工列表
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    beforeInit() {
      this.url = 'api/team-list'
      const sort = 'create_time,desc'
      this.params = { page: this.page, size: this.size, sort: sort, create_id: this.user.user_id }
      return true
    },
    resetForm() {
      this.dialog = false
    },
    cancel() {
      this.resetForm()
    },
    doSubmit() {
      // 获取表格选中的id
      const dataSelect = this.$refs.table.selection
      const array = []
      for (let i = 0; i < dataSelect.length; i++) {
        array.push(dataSelect[i])
      }
      this.$emit('callBackAdd', array)
      this.resetForm()
    }
  }
}
</script>

<style scoped>

</style>
